package com.imooc.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;

/**
 * @Author 14048
 * @Date 2022/1/13 14:38
 */
@Configuration
public class GateWayConfig {


    @Autowired
    private AuthFilter authFilter;

    @Bean
    @Order
    public RouteLocator customizedRoutes(RouteLocatorBuilder builder){

//        return builder.routes()
//                .route(
//                        r->r.path("/seckill/**")
//                                //启动后的1小时内
//                                .and().after(ZonedDateTime.now().plusMinutes(1))
//                                // 在2个时间点之内生效
//                                //.and().between()
//                                .filters(f->f.stripPrefix(1))
//                                .uri("lb://eureka-client")
//                ).build();
  

        return builder.routes()
                .route(
                        r->r.path("/eurekaClient/**")
                                .filters(f->f.filter(authFilter))
                                .uri("lb://eureka-client")
                )
                .build();
    }
}
